package cn.ac.siom.query.action;

import cn.ac.siom.query.service.ITabWeblibService;
import cn.ac.siom.query.util.action.DefaultAction;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * Created by guo.chen on 2018/8/14 0014.
 */
@Controller
@RequestMapping("/weblib/*")
public class TabWeblibAction extends DefaultAction{
    Logger logger = Logger.getLogger(TabWeblibAction.class);

    @Resource
    private ITabWeblibService tabWeblibService;

    @ResponseBody
    @RequestMapping(value="selectWeblib", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public Map selectWeblib(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        try{
            Map params=getParameterMap(request);
            if("slcshuju".equals(params.get("leibie"))){
                insertAccessinfo(request,"首页科学数据");
            }else if("slcxm".equals(params.get("leibie"))){
                insertAccessinfo(request,"首页重要项目");
            }else {
                insertAccessinfo(request,"首页网络资源");
            }
            return this.tabWeblibService.selectWeblib(params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("网络资源信息查询失败",e);
            return null;
        }
    }

    @ResponseBody
    @RequestMapping(value="selectCount", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public Integer selectCount(HttpServletRequest request) {
        try{
            Map params=getParameterMap(request);
            return this.tabWeblibService.selectCount(params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("网络资源数据总条数查询失败",e);
            return -1;
        }
    }

    @Override
    public String getText() {
        return null;
    }
}
